//This code was created with the help of Cairngorm Creator by Tyler Beck.
//The portions of this document created by Cairngorm Creator 
//are provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
//CONDITIONS OF ANY KIND, either express or implied.
//========================================================



package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.EditBillingEvent;
	import net.optix.ip.events.GetUserEvent;
	import net.optix.ip.model.ModelLocator;

	public class EditBillingCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:EditBillingEvent	=	EditBillingEvent(event);
			
			var delegate:UserDelegate	=	new UserDelegate();
			
			delegate.editBilling(this,myEvent.vo);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			try
			{
				var	result:int	=	event.result.result;
				switch(result)
				{
					case -2:
						model.result	=	"Access Denied .";
						break;
					case 0:
						model.result	=	"Program error";
						break;
					case 1:
						model.result	=	"Successfully saved company information !";
						model.close		=	"no";
						model.close		=	"yes";
						
						var getUser:GetUserEvent	=	new GetUserEvent(model.user.userID);
						com.adobe.cairngorm.control.CairngormEventDispatcher.getInstance().dispatchEvent(getUser);
						break;
				}
			}
			catch(error:Error)
			{
				model.result	=	"Program error";
			}
			
			model.bSubmit	=	true;
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			
			trace(event.result);
			
		}

	}
}